package com.qianfeng;

import java.util.Date;

public class TestString {

    public static void main(String[] args) {
        System.out.println("===========");
        String str = "中华人民共和国";
        String str2 = "我是中国人";
        Date beginDate = new Date();
        for (int i = 0; i < 50000; i++) {
            str += str2;
        }
        Date endDate = new Date();

        System.out.println("string拼接的运行时间：" + (endDate.getTime() - beginDate.getTime()));

        StringBuffer sb = new StringBuffer(str);
        Date beginDate1 = new Date();
        for (int i = 0; i < 50000; i++) {
            sb.append(str2);
        }
        Date endDate1 = new Date();
        System.out.println("stringbuffer的拼接时间：" + (endDate1.getTime() - beginDate1.getTime()));
    }
}
